package com.tanhua.admin.task;


import com.tanhua.admin.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
    定义任务类
    1. 类要交给容器管理
    2. 编写定时执行的java方法
  */
@Component
public class AnalysisTask {
    @Autowired
    private AnalysisService analysisService;

    //每小时，计算日志表数据写入统计表
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void analysis() throws ParseException {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("当前时间：" + format);

        //调用service完成数据统计
        analysisService.analysis();
    }
}
